package com.dingwen.treasure.business.controller;

import com.dingwen.treasure.base.controller.BaseViewController;
import com.dingwen.treasure.base.pojo.vo.Result;
import com.dingwen.treasure.open.api.sms.aliyun.bo.AliSmsSendBo;
import com.dingwen.treasure.open.api.sms.aliyun.config.AliyunSmsConfig;
import com.dingwen.treasure.open.api.sms.service.SmsService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 短信API
 *
 * @author dingwen
 * @date 2022/12/09
 */
@Api(tags = "短信API")
@RestController
@RequestMapping
public class SmsController implements BaseViewController {

    @Resource(name = "aliyunSmsService")
    private SmsService<AliSmsSendBo, String, Object> aliyunSmsService;

    @Resource
    private AliyunSmsConfig aliyunSmsConfig;


    @PutMapping("ali-smss/{phone}")
    public Result<String> aliyunSmsSend(@PathVariable("phone") String phone) {
        AliSmsSendBo aliSmsSendBo = AliSmsSendBo.builder()
                .phoneNumber(phone)
                .singName(aliyunSmsConfig.getSignNameTreasure())
                .templateCode(aliyunSmsConfig.getTemplateCodeWelcome())
                // 当前短信模版不支持参数（传入Json即可）
                //.templateParam()
                .build();
        aliyunSmsService.send(aliSmsSendBo);
        return success();
    }
}
